package com.library.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.library.entity.StudentInfo;
import com.library.entity.CourseSchedule;
import com.library.mapper.CourseScheduleMapper;
import com.library.vo.CourseReq;
import com.library.vo.P;
import com.library.vo.StudentInfoReq;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseScheduleService {

    @Autowired
    private CourseScheduleMapper courseScheduleMapper;

    public P<List<CourseSchedule>> list(CourseReq studentInfo) {
        Page<Object> objects = PageHelper.startPage(studentInfo.getPageNum(), studentInfo.getPageSize());
        CourseSchedule userInfo = new CourseSchedule();
        BeanUtils.copyProperties(studentInfo,userInfo);
        List<CourseSchedule> studentInfos = this.courseScheduleMapper.selectByQuery(userInfo);
        P p = P.valueOf((Page) studentInfos);
        return p;
    }

    public void add(CourseSchedule studentInfo) {
        int i = courseScheduleMapper.insertSelective(studentInfo);
    }

    public void delete(CourseSchedule studentInfo) {
        this.courseScheduleMapper.deleteByPrimaryKey(studentInfo.getId());
    }

    public void update(CourseSchedule studentInfo) {
        this.courseScheduleMapper.updateByPrimaryKeySelective(studentInfo);
    }

    public CourseSchedule detail(CourseSchedule studentInfo) {
        CourseSchedule studentInfo1 = this.courseScheduleMapper.selectByPrimaryKey(studentInfo.getId());
        return studentInfo1;
    }

}
